SET(CSHARP_FLAGS "/lib:${INTERFACE_CSHARP_BUILD_DIR};/r:shogun")

# add test case for each generated example
# (not generated yet so have to fake filenames from META_EXAMPLES list)
FOREACH(META_EXAMPLE ${META_EXAMPLES})
    # assume a structure <target_language>/<category>/listing.sg
    GET_META_EXAMPLE_VARS(${META_EXAMPLE} EXAMPLE_NAME EXAMPLE_REL_DIR EXAMPLE_NAME_WITH_DIR)

	set(COMPILED_CSHARP_EXAMPLE ${CMAKE_CURRENT_BINARY_DIR}/${EXAMPLE_REL_DIR}/${EXAMPLE_NAME}.exe)
	set(CSHARP_META_EXAMPLE_SOURCE ${CMAKE_BINARY_DIR}/examples/meta/csharp/${EXAMPLE_REL_DIR}/${EXAMPLE_NAME}.cs)

	ADD_CUSTOM_COMMAND(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${EXAMPLE_REL_DIR}/${EXAMPLE_NAME}.exe
		COMMAND	${CSHARP_COMPILER} ${EXAMPLE_NAME}.cs ${CSHARP_FLAGS} -out:${EXAMPLE_NAME}.exe
		DEPENDS interface_csharp shogun meta_examples ${CSHARP_META_EXAMPLE_SOURCE}
		WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/${EXAMPLE_REL_DIR})

	ADD_CUSTOM_TARGET(csharp_${EXAMPLE_NAME} ALL
		DEPENDS ${COMPILED_CSHARP_EXAMPLE})

	LIST(APPEND CSHARP_EXAMPLES csharp_${EXAMPLE_NAME})

	add_test(NAME generated_csharp-${EXAMPLE_NAME_WITH_DIR}
		WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/${EXAMPLE_REL_DIR}
		COMMAND ${CSHARP_INTERPRETER} ${CMAKE_CURRENT_BINARY_DIR}/${EXAMPLE_REL_DIR}/${EXAMPLE_NAME}.exe)
	set_property(TEST generated_csharp-${EXAMPLE_NAME_WITH_DIR} PROPERTY
        ENVIRONMENT "MONO_PATH=${INTERFACE_CSHARP_BUILD_DIR}")
ENDFOREACH()

add_custom_target(build_csharp_meta_examples ALL
				 DEPENDS ${CSHARP_EXAMPLES}
				 COMMENT "Compiled generated C# examples")
